package com.youlemall.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youlemall.common.pojo.PageResult;
import com.youlemall.mapper.SellerMapper;
import com.youlemall.pojo.Seller;
import com.youlemall.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**商家后台实现类
 * 2 * @Author: kevin
 * 3 * @Date: 2019/7/18 17:40
 * 4
 */

@Service
@Transactional
public class SellerServiceImpl implements SellerService {

	@Autowired
	private SellerMapper sellerMapper;

	@Override
	public void save(Seller seller) {
		try {
			seller.setStatus("0");
			seller.setCreateTime(new Date());
			sellerMapper.insertSelective(seller);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void update(Seller seller) {

	}

	@Override
	public void delete(Serializable id) {

	}

	@Override
	public void deleteAll(Serializable[] ids) {

	}

	@Override
	public Seller findOne(Serializable id) {
		return sellerMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Seller> findAll() {
		return null;
	}

	@Override
	public PageResult findByPage(Seller seller, int page, int rows) {
		PageInfo<Seller> pageInfo = null;
		try {
			pageInfo = PageHelper.startPage(page, rows).doSelectPageInfo(new ISelect() {
				@Override
				public void doSelect() {
					sellerMapper.findAll(seller);
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new PageResult(pageInfo.getPages(),pageInfo.getList());
	}

	@Override
	public void updateStatus(Seller seller) {
		sellerMapper.updateStatus(seller);
	}
}
